package com.anolesoft.amljmes.fortyone.service.mapper;

import java.util.Date;
import java.util.List;
import java.util.Set;

import com.anolesoft.amljmes.fortyone.dto.*;
import com.anolesoft.amljmes.fortyone.vo.FortyoneApplyVo;
import com.anolesoft.amljmes.fortyone.vo.FortyoneVo;
import com.anolesoft.amljmes.fortyone.vo.MesQualityUpdatelogVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.jdbc.SQL;

import com.anolesoft.amljmes.fortyone.controller.MesStoveBaseController;
import com.anolesoft.amljmes.fortyone.dto.StoveQueryParamDto.StoveConditionDto;
import com.anolesoft.amljmes.fortyone.dto.FortyoneApplyDto.ApplyConditionDto;
import com.anolesoft.amljmes.fortyone.entity.MesStoveBase;
import com.anolesoft.amljmes.fortyone.entity.MesStoveFabinfo;
import com.anolesoft.amljmes.fortyone.vo.StoveVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.hutool.core.util.StrUtil;

@Mapper
public interface MesStoveBaseServiceMapper {
	/**
	 * 状态更改为完检
	 * @param objuid
	 * @return
	 */
	@Update("    update mes_stove_base" + "      set state = 5" + "    where objuid = #{objuid, jdbcType=VARCHAR}")
	int updateMesStoveFabinfosStateWj(String objuid);
	// 根据id查询
	@Select("select t.objuid,t.furnaceid,t.gyffjc,t.devicename,t.deviceid,t.plant from mes_stove_base t where upper(t.objuid) = upper(#{objuid, jdbcType=VARCHAR})")
	MesStoveBaseDto queryMesStoveBaseById(String objuid);

	// 根据炉次编号查询
	@Select("select t.* from mes_stove_base t where upper(t.furnaceid) = upper(#{furnaceid, jdbcType=VARCHAR})")
	MesStoveBaseDto queryMesStoveBaseByLc(String furnaceid);

	// 根据工艺方法简称查询
	@Select("select t.* from mes_stove_base t where upper(t.gyffjc) = upper(#{gyffjc, jdbcType=VARCHAR})")
	MesStoveBaseDto queryMesStoveBaseByGyffjc(String gyffjc);

	// 根据设备名称查询
	@Select("select t.* from mes_stove_base t where upper(t.devicename) = upper(#{devicename, jdbcType=VARCHAR})")
	MesStoveBaseDto queryMesStoveBaseBySbmc(String devicename);

	// 根据所在厂房查询
	@Select("select t.* from mes_stove_base t where upper(t.plant) = upper(#{plant, jdbcType=VARCHAR})")
	MesStoveBaseDto queryMesStoveBaseBySzcf(String plant);

	// 根据派工时间查询
	@Select("select t.* from mes_stove_base t where upper(t.pgsj) = upper(#{pgsj, jdbcType=DATE})")
	MesStoveBaseDto queryMesStoveBaseByPgsj(Date pgsj);

	// 根据id修改状态、开工时间
	@Update("    update mes_stove_base" + "      set state = 2,kgsj = sysdate,kgr = #{kgr, jdbcType=VARCHAR}"
			+ "    where objuid = #{objuid, jdbcType=VARCHAR}")
	int updateMesStoveBaseKg(@Param("objuid") String objuid,@Param("kgr") String kgr);

	// 根据id修改状态、完工时间
	@Update("    update mes_stove_base" + "      set state = 3,wgsj = sysdate"
			+ "    where objuid = #{objuid, jdbcType=VARCHAR}")
	int updateMesStoveBaseWg(String objuid);

	// 根据id修改状态、派工时间
	@Update("    update mes_stove_base" + "      set state = 1,pgsj = sysdate"
			+ "    where objuid = #{objuid, jdbcType=VARCHAR}")
	int updateMesStoveBasePg(String objuid);

	// 根据id修改状态
	@Update("    update mes_stove_base" + "      set state = 4,txr = #{txr, jdbcType=VARCHAR},txsj = sysdate"
			+ "    where objuid = #{objuid, jdbcType=VARCHAR}")
	int updateMesStoveBaseStateTx(MesStoveBaseDto inFoDtoParam);

	@Update("    update mes_stove_base" + "      set state = 5,jyr = #{jyr, jdbcType=VARCHAR},jysj = sysdate"
			+ "    where objuid = #{objuid, jdbcType=VARCHAR}")
	int updateMesStoveBaseStateJy(MesStoveBaseDto inFoDtoParam);

	// 选择设备动态下拉
	@Select("select * from bas_rcl_machines where factory_id = #{factoryId, jdbcType=VARCHAR}")
	List<BasRclMachinesDto> MachinesnameAll(String factoryId);

	@SelectProvider(type = createSQL.class, method = "queryMesStoveBaseSQL")
	List<MesStoveBaseDto> queryMesStoveBaseSQL(MesStoveBaseController.DemoVO demoVO);

	@Select("select * from mes_stove_fabinfo where stoye_fabinfo_obj = #{stoyeFabinfoObj, jdbcType=VARCHAR}")
	List<FortyoneVo> getFortyoneList(String stoyeFabinfoObj);

	@Select("select stoye_fabinfo_obj from mes_stove_quality where objuid = #{objuid, jdbcType=VARCHAR}")
	String getStoyeFabinfoObj(String objuid);

	@SelectProvider(type = createSQL.class, method = "getYzSQL")
	String getYz(@Param("objuid") String objuid, @Param("zljl") String zljl);

	@Select("select t.*, a.furnaceid, b.gxmgjzf from mes_stove_quality t join mes_stove_base a on t.stoye_fabinfo_obj = a.objuid join mes_gjgyxx_fksz b on a.gjgyxx_obj = b.objuid where t.objuid = #{objuid, jdbcType=VARCHAR}")
	FortyoneApplyVo queryByobjuid(String objuid);

	@Update("    update mes_quality_updatelog" + "      set zt = #{zt},shr = #{id, jdbcType=VARCHAR},shsj = sysdate"
			+ "    where objuid = #{objuid, jdbcType=VARCHAR}")
	void updateModifyApply(@Param("objuid") String objuid, @Param("id") String id, @Param("zt") Integer zt);

	@Select("select * from mes_quality_updatelog where objuid = #{objuid, jdbcType=VARCHAR}")
	MesQualityUpdatelogVo queryLogVoByObjuid(String objuid);

	@Update("    update mes_quality_updatelog" + "      set zt = #{zt},spr = #{id, jdbcType=VARCHAR},spsj = sysdate"
			+ "    where objuid = #{objuid, jdbcType=VARCHAR}")
	void updateModifyApply1(@Param("objuid") String objuid, @Param("id") String id, @Param("zt") Integer zt);

	@UpdateProvider(type = createSQL.class, method = "updateQualitySQL")
	void updateQuality(@Param("zlxxzj") String zlxxzj, @Param("zdm") String zdm, @Param("ggh") String ggh);

	@Select("select t.* from mes_stove_quality t where t.objuid = #{objuid, jdbcType=VARCHAR}")
	FortyoneApplyVo queryByobjuid1(String objuid);


	public static class createSQL {
		public static String queryMesStoveBaseSQL(MesStoveBaseController.DemoVO demoVO) {
			return new SQL() {
				{
					StringBuilder sql = new StringBuilder();
					sql.append(" a.objuid as key,a.objuid, a.furnaceid, a.gyffjc, a.devicename, "
							+ "a.deviceid, a.plant, a.gongduan, a.state, a.cjr, a.cjsj, a.quantity, "
							+ "a.kgsj, a.wgsj, a.pgr, a.pgsj, a.factory_id, 0 as pageNo,10 as pageSize,b.sl   "
							+ "from mes_stove_base a "
							+ "left join (select FORTYONE_CODE,STOYE_FABINFO_OBJ ,count(1)||'/'||sum(nvl(yssl,0)) sl from mes_stove_fabinfo group by STOYE_FABINFO_OBJ,FORTYONE_CODE) b "
							+ "on a.objuid = b.STOYE_FABINFO_OBJ "
							+ "where 1=1 and a.factory_id = #{factoryId, jdbcType=VARCHAR} ");
					if (!StrUtil.isEmptyOrUndefined(demoVO.getFurnaceid())) {
						String furnaceid = demoVO.getFurnaceid();
						sql.append(" and upper(a.furnaceid) = upper(trim(#{furnaceid, jdbcType=VARCHAR}))");
					}
					if (!StrUtil.isEmptyOrUndefined(demoVO.getGyffjc())) {
						String gyffjc = demoVO.getGyffjc();
						sql.append(" and upper(a.gyffjc) = upper(#{gyffjc, jdbcType=VARCHAR})");
					}
					if (!StrUtil.isEmptyOrUndefined(demoVO.getMachinesname())) {
						String devicename = demoVO.getMachinesname();
						sql.append(
								" and upper(a.devicename) like upper('%'||trim(#{machinesname, jdbcType=VARCHAR})||'%')");
					}
					if (!StrUtil.isEmptyOrUndefined(demoVO.getPlant())) {
						String plant = demoVO.getPlant();
						sql.append(" and upper(a.plant) = upper(trim(#{plant, jdbcType=VARCHAR}))");
					}
					if (!StrUtil.isEmptyOrUndefined(demoVO.getFortyoneCode())) {
						String fortyoneCode = demoVO.getFortyoneCode();
						sql.append(" and upper(b.fortyone_code) = upper(#{fortyoneCode, jdbcType=VARCHAR})");
					}
					if (demoVO.getPgsj() != null) {
						sql.append(" and a.pgsj = #{pgsj, jdbcType=DATE}");
					}
					SELECT(sql.toString());
				}
			}.toString();
		}

		public static String queryStoveVosByConditionSQL(@Param("condition") StoveConditionDto condition) {
			return new SQL() {
				{
					SELECT("t.objuid", "t.state", "t.quantity", "t.furnaceid", "t.pgsj", "t.kgsj", "t.wgsj", "t.cjsj");
					SELECT("a.gyffjc", "a.gxmgjzf", "b.machinescode", "b.machinesname", "b.workshop", "b.deptid","t2.name as kgr");
					SELECT("c.name as pgr");
					FROM("mes_stove_base t");
					LEFT_OUTER_JOIN("stf_employee t2 on t.kgr = t2.objuid");
					INNER_JOIN("mes_gjgyxx_fksz a on t.gjgyxx_obj = a.objuid");
					INNER_JOIN("bas_rcl_machines b on t.device_uid = b.objuid");
					LEFT_OUTER_JOIN("stf_employee c on t.pgr = c.objuid");
					WHERE("t.factory_id = #{condition.factoryId}");
					if (!StrUtil.isEmptyOrUndefined(condition.getGjgyxxObj())) {
						WHERE("t.gjgyxx_obj = #{condition.gjgyxxObj}");
					}
					if (!StrUtil.isEmptyOrUndefined(condition.getFabrecordid())) {
						WHERE("exists (select d.objuid from mes_stove_fabinfo d where instr(d.fortyone_code, #{condition.fabrecordid}) > 0)");
					}
					if (!StrUtil.isEmptyOrUndefined(condition.getStart())) {
						WHERE("t.pgsj >= to_date(#{condition.start}, 'yyyy-mm-dd')");
					}
					if (!StrUtil.isEmptyOrUndefined(condition.getEnd())) {
						WHERE("t.pgsj <= to_date(#{condition.end}, 'yyyy-mm-dd')");
					}
					if (!StrUtil.isEmptyOrUndefined(condition.getKeyWord())) {
						WHERE("instr(upper(a.gxmgjzf||t.furnaceid||b.machinesname||b.workshop), upper(#{condition.keyWord})) > 0");
					}
					if (condition.getState() != null) {
						WHERE("t.state = #{condition.state}");
					}
					ORDER_BY("t.cjsj desc", "t.state");
				}
			}.toString();
		}


		public static String getYzSQL(@Param("objuid") String objuid, @Param("zljl") String zljl) {
			return new SQL() {
				{
					SELECT(zljl);
					FROM("mes_stove_quality t");
					WHERE("t.objuid = #{objuid, jdbcType=VARCHAR}");
				}
			}.toString();
		}



		public static String updateQualitySQL(@Param("zlxxzj") String zlxxzj, @Param("zdm") String zdm, @Param("ggh") String ggh) {
			return new SQL() {
				{
					UPDATE("mes_stove_quality");
					SET(zdm + " = #{ggh, jdbcType=VARCHAR}");
					WHERE("objuid = #{zlxxzj, jdbcType=VARCHAR}");
				}
			}.toString();
		}



		public static String queryFortyoneApplyVosByConditionSQL(@Param("condition") ApplyConditionDto condition) {
			return new SQL() {
				{
					SELECT("t.*", "t.objuid as id", "a.furnaceid", "a.state", "b.gxmgjzf", "a.txr", "a.txsj");
					FROM("mes_stove_quality t");
					LEFT_OUTER_JOIN("mes_stove_base a on t.stoye_fabinfo_obj = a.objuid");
					LEFT_OUTER_JOIN("mes_gjgyxx_fksz b on a.gjgyxx_obj = b.objuid");
					if (!StrUtil.isEmptyOrUndefined(condition.getFurnaceid())) {
						WHERE("a.furnaceid = #{condition.furnaceid}");
					}
					if (!StrUtil.isEmptyOrUndefined(condition.getFortyoneCode())) {
						WHERE("t.fortyone_code = #{condition.fortyoneCode}");
					}
					ORDER_BY("a.furnaceid", "a.state", "t.fortyone_code");
				}
			}.toString();
		}


		public static String queryFortyoneExamineVosByConditionSQL(@Param("condition") ApplyConditionDto condition) {
			return new SQL() {
				{
					SELECT("t.*");
					FROM("mes_quality_updatelog t");
					WHERE("t.zt = 0");
					if (!StrUtil.isEmptyOrUndefined(condition.getFurnaceid())) {
						WHERE("t.lcbh = #{condition.furnaceid}");
					}
					if (!StrUtil.isEmptyOrUndefined(condition.getFortyoneCode())) {
						WHERE("t.zzjl = #{condition.fortyoneCode}");
					}
					ORDER_BY("t.zt");
				}
			}.toString();
		}


		public static String queryFortyoneAdoptVosByConditionSQL(@Param("condition") ApplyConditionDto condition) {
			return new SQL() {
				{
					SELECT("t.*");
					FROM("mes_quality_updatelog t");
					WHERE("t.zt = 3");
					if (!StrUtil.isEmptyOrUndefined(condition.getFurnaceid())) {
						WHERE("t.lcbh = #{condition.furnaceid}");
					}
					if (!StrUtil.isEmptyOrUndefined(condition.getFortyoneCode())) {
						WHERE("t.zzjl = #{condition.fortyoneCode}");
					}
					ORDER_BY("t.zt");
				}
			}.toString();
		}


		public static String queryFortyoneHistoryVosByConditionSQL(@Param("condition") ApplyConditionDto condition) {
			return new SQL() {
				{
					SELECT("t.*");
					FROM("mes_quality_updatelog t");
					if (!StrUtil.isEmptyOrUndefined(condition.getFurnaceid())) {
						WHERE("t.lcbh = #{condition.furnaceid}");
					}
					if (!StrUtil.isEmptyOrUndefined(condition.getFortyoneCode())) {
						WHERE("t.zzjl = #{condition.fortyoneCode}");
					}
					ORDER_BY("t.zt");
				}
			}.toString();
		}


		public static String updateStateAndCountSQL(@Param("mesStoveBase") MesStoveBase mesStoveBase) {
			return new SQL() {
				{
					UPDATE("mes_stove_base");
					if (mesStoveBase.getState() != null) {
						SET("state = #{mesStoveBase.state}");
					}
					SET("quantity = #{mesStoveBase.quantity}");
					SET("pgr = #{mesStoveBase.pgr}");
					SET("pgsj = #{mesStoveBase.pgsj}");
					WHERE("objuid = #{mesStoveBase.objuid}");
				}
			}.toString();
		}
	}

	/**
	 * 删除炉次
	 * 
	 * @param objuid
	 * @return
	 */
	@Delete("delete mes_stove_base where objuid = #{objuid} ")
	void deleteMesStoveBase(String objuid);

	// 新增炉次
	@Insert("    insert into mes_stove_base"
			+ "      (objuid, furnaceid, gyffjc, devicename, deviceid, plant, gongduan, cjr, factory_id)" + "    values"
			+ "      (sys_guid(), 'LC'||to_char(sysdate,'yyyy-mm-dd')||lpad(seq_lc_code.nextval,4,0), "
			+ "#{gyffjc, jdbcType=VARCHAR}, #{devicename, jdbcType=VARCHAR}, "
			+ "#{deviceid, jdbcType=VARCHAR}, #{plant, jdbcType=VARCHAR}, #{gongduan, jdbcType=VARCHAR}, "
			+ "#{cjr, jdbcType=VARCHAR},#{factoryId, jdbcType=VARCHAR})")
	int addMesStoveBase(MesStoveBaseDto inFoDtoParam);
//    @Select(" select machinescode from bas_rcl_machines a where a.machinescode = #{machinescode, jdbcType=VARCHAR} ")
//    String querySbbh(@Param("machinescode") String machinescode);


	@Insert("    insert into mes_quality_updatelog"
			+ "      (objuid, lcbh, lczj, gxmgjzf, zzjl, gxh, gxm, ggnr, zdm, ggq, ggh, sqr, sqsj, zt, shr, shsj, spr, spsj, cdh, zlxxzj)"
			+ "    values"
			+ "      (sys_guid(), #{lcbh, jdbcType=VARCHAR}, #{lczj, jdbcType=VARCHAR}, #{gxmgjzf, jdbcType=VARCHAR}, #{zzjl, jdbcType=VARCHAR},"
			+ "#{gxh, jdbcType=VARCHAR}, #{gxm, jdbcType=VARCHAR}, #{ggnr, jdbcType=VARCHAR},#{zdm, jdbcType=VARCHAR},"
			+ "#{ggq, jdbcType=VARCHAR}, #{ggh, jdbcType=VARCHAR}, #{sqr, jdbcType=VARCHAR}, sysdate,"
			+ "#{zt}, #{shr, jdbcType=VARCHAR}, #{shsj}, #{spr, jdbcType=VARCHAR},"
			+ "#{spsj}, #{cdh, jdbcType=VARCHAR}, #{zlxxzj, jdbcType=VARCHAR})")
	void saveModifyApply(MesQualityUpdatelogVo vo);

	// 查询厂房，工段
	@Select("select t.machinescode,t.deptid,t.workshop from bas_rcl_machines  t where "
			+ "t.machinescode = #{machinescode, jdbcType=VARCHAR} and t.factory_id = #{factoryId, jdbcType=VARCHAR}")
	BasRclMachinesDto queryBasRclMachines(@Param("machinescode") String machinescode,
			@Param("factoryId") String factoryId);

	/**
	 * 新增炉次
	 * 
	 * @param mesStoveBase
	 */
	@Insert("insert into mes_stove_base\r\n"
			+ "  (objuid, furnaceid, gyffjc, devicename, deviceid, plant, gongduan, state, cjr, cjsj, quantity, kgsj, wgsj, factory_id, pgr, pgsj, gjgyxx_obj, txr, txsj, jyr, jysj, kgr, wgr, device_uid)\r\n"
			+ "values\r\n"
			+ "  (#{objuid}, 'LC'||to_char(sysdate,'yyyy-mm-dd')||lpad(seq_lc_code.nextval,4,0), #{gyffjc}, #{devicename}, #{deviceid}, #{plant}, #{gongduan}, #{state}, #{cjr}, #{cjsj}, #{quantity}, #{kgsj}, #{wgsj}, #{factoryId}, #{pgr}, #{pgsj}, #{gjgyxxObj}, #{txr}, #{txsj}, #{jyr}, #{jysj}, #{kgr}, #{wgr}, #{deviceUid})")
	void save(MesStoveBase mesStoveBase);

	@SelectProvider(type = createSQL.class, method = "queryStoveVosByConditionSQL")
	List<StoveVo> queryStoveVosByCondition(@Param("condition") StoveConditionDto condition, Page<StoveVo> page);

	@SelectProvider(type = createSQL.class, method = "queryFortyoneApplyVosByConditionSQL")
	List<FortyoneApplyVo> queryFortyoneApplyVosByCondition(@Param("condition") ApplyConditionDto condition, Page<FortyoneApplyVo> page);

	@SelectProvider(type = createSQL.class, method = "queryFortyoneExamineVosByConditionSQL")
	List<MesQualityUpdatelogVo> queryFortyoneExamineVosByCondition(@Param("condition") ApplyConditionDto condition, Page<MesQualityUpdatelogVo> page);

	@SelectProvider(type = createSQL.class, method = "queryFortyoneAdoptVosByConditionSQL")
	List<MesQualityUpdatelogVo> queryFortyoneAdoptVosByCondition(@Param("condition") ApplyConditionDto condition, Page<MesQualityUpdatelogVo> page);

	@SelectProvider(type = createSQL.class, method = "queryFortyoneHistoryVosByConditionSQL")
	List<MesQualityUpdatelogVo> queryFortyoneHistoryVosByCondition(@Param("condition") ApplyConditionDto condition, Page<MesQualityUpdatelogVo> page);


	/**
	 * 根据制造记录条码和厂id 锁定这本制造制造记录当前的
	 * 
	 * @param fabrecordid
	 * @param factoryId
	 * @return
	 */
	@Select("select * from (\n" +
					"select t.objuid as mes_order_trace_uid, t.fabrecordid,\n" + 
					"    t.curgongxu, t.assignmentid,t.jx,t.partid, t.putnum + nvl(t.trial_num, 0) + nvl(t.shiliao_num, 0) +\n" + 
					"    nvl(t.shibang, 0) - nvl(t.pohuai_num, 0) + nvl(t.ddj_num, 0) +\n" + 
					"    nvl(t.jieyu_num, 0) - nvl(t.tk_num, 0) - nvl(t.z_ddj_num, 0) -\n" + 
					"    nvl(t.diushi_num, 0) - nvl(t.buhege_num, 0) - nvl(t.refuse_num, 0) put_num,\n" + 
					"    a.objuid as mes_process_trace_uid,a.biaoji,a.processname,b.ordercode,rownum as aa\n" + 
					"    from mes_order_trace t\n" + 
					"    inner join pln_order_code b on t.fabrecordid = b.plancode2\n" + 
					"    inner join mes_process_trace a on  t.objuid=a.ordertraceuid\n" + 
					"    where a.processstate=0  and b.factory_id = #{factoryId} and  t.fabrecordid = #{fabrecordid}\n" + 
					"order by case when length(regexp_substr(a.processno,'^\\s*[[:digit:]]+',1, 1)) > 0 then\n" +
					"     to_number(to_single_byte(regexp_substr(a.processno,'^\\s*[[:digit:]]+',1,1)))\n" + 
					"      else case when regexp_instr(a.processno, '[()]') > 0 then\n" + 
					"           to_number(regexp_replace(a.processno,'[()]','')) else 9999999 end end,\n" + 
					"           case when instr(a.processno, '-') > 0 then to_number(substr(a.processno,\n" + 
					"               instr(a.processno, '-') + 1)) else 0 end,\n" + 
					"           case when instr(a.processno, '') > 0 then to_number(substr(a.processno,\n" + 
					"               instr(a.processno, '') + 1)) else 0 end,\n" + 
					"           case when instr(a.processno, '') > 0 then to_number(substr(a.processno,\n" + 
					"                instr(a.processno, '') + 1)) else 0 end, a.processno\n" + 
					") where aa = 1")
	MesOrderTraceInfoDto queryMesOrderTraceInfoDto(@Param("fabrecordid") String fabrecordid,
			@Param("factoryId") String factoryId);

	/**
	 * 根据炉次主键，查找当前炉次下所有制造记录
	 * 
	 * @param mesStoveBaseUid
	 * @return
	 */
	@Select("select t.* from mes_stove_fabinfo t where t.stoye_fabinfo_obj = #{mesStoveBaseUid}")
	List<MesStoveFabinfo> queryMesStoveFabinfos(@Param("mesStoveBaseUid") String mesStoveBaseUid);

	/**
	 * 查询一个制造记录工序在哪些炉次下派工
	 * 
	 * @param mesProcessTraceUid
	 * @param mesStoveBaseUid
	 */
	@Select("select b.furnaceid\r\n" + "  from mes_stove_fabinfo t\r\n" + "  join mes_stove_base b\r\n"
			+ "    on t.stoye_fabinfo_obj = b.objuid\r\n"
			+ " where t.mes_process_uid = #{mesProcessTraceUid} and b.objuid != #{mesStoveBaseUid}")
	List<String> queryFurnaceidsByMesProcessTraceUid(@Param("mesProcessTraceUid") String mesProcessTraceUid,
			@Param("mesStoveBaseUid") String mesStoveBaseUid);

	/**
	 * 根据主键查询炉次信息
	 * 
	 * @param mesStoveBaseUid
	 * @return
	 */
	@Select("select * from mes_stove_base where objuid = #{mesStoveBaseUid}")
	MesStoveBase queryMesStoveBaseByObjuid(@Param("mesStoveBaseUid") String mesStoveBaseUid);

	@Select("select a.state, a.objuid, \r\n" + "       (select count(1)\r\n" + "          from mes_stove_fabinfo b\r\n"
			+ "         where b.stoye_fabinfo_obj = #{objuid}) as quantity\r\n" + "  from mes_stove_base a\r\n"
			+ " where a.objuid = #{objuid}")
	MesStoveBase queryDispatchCountAndState(@Param("objuid") String objuid);

	@UpdateProvider(type = createSQL.class, method = "updateStateAndCountSQL")
	void updateStateAndCount(@Param("mesStoveBase") MesStoveBase mesStoveBase);
	
	@Select("select b.gxmgjzf\r\n" + 
			"  from mes_stove_base a\r\n" + 
			"  join mes_gjgyxx_fksz b\r\n" + 
			"    on a.gjgyxx_obj = b.objuid\r\n" + 
			" where a.objuid = #{objuid}")
	String getProcessNameByObjuid(@Param("objuid") String objuid);

	@Update("update mes_stove_base\r\n" + 
			"   set txr = #{mesStoveBase.txr}, txsj = sysdate\r\n" + 
			" where objuid = #{mesStoveBase.objuid}")
	void updateQualityTxr(@Param("mesStoveBase") MesStoveBase mesStoveBase);
	
	@Select("select a.a.name as emp_name,\r\n" + 
			"       a.eid    as emp_id,\r\n" + 
			"       b.name   as checker_name,\r\n" + 
			"       b.eid    as checker_eid\r\n" + 
			"  from (select t.txr, t.jyr from mes_stove_base t where t.objuid = #{objuid}) v\r\n" + 
			"  left join stf_employee a\r\n" + 
			"    on v.txr = a.objuid\r\n" + 
			"  left join stf_employee b\r\n" + 
			"    on v.jyr = b.objuid")
	EmpDto queryEmpDtoByObjuid(@Param("objuid") String objuid);
	
	@Update("update mes_stove_base t set t.state = #{mesStoveBase.state} where objuid = #{mesStoveBase.objuid}")
	void updateState(@Param("mesStoveBase") MesStoveBase mesStoveBase);
	
	@Select("select objuid from STF_EMPLOYEE t where t.password2 = #{checkCode}")
	String queryEmpDtoByCheckCode(String checkCode);

	@Update("update mes_stove_base\r\n" + 
			"   set jyr = #{mesStoveBase.jyr}, jysj = #{mesStoveBase.jysj}\r\n" + 
			" where objuid = #{mesStoveBase.objuid}")
	void updateJyr(@Param("mesStoveBase") MesStoveBase mesStoveBase);
}
